package sceneGraph;

import javax.media.j3d.Transform3D;
import javax.vecmath.AxisAngle4f;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

public class Moon extends AbstractPlanet implements ISceneObject {

	Point3f parentPos = new Point3f(0, 0, 0);

	public Moon(float radius, Point3f pos, Color3f kDiffuse, Color3f kSpecular, Color3f kAmbient, float nShineness, boolean isSun, Vector3f orbitAxis,
			float orbitSpeed, String textureFilePath, String heightMapFilePath) {
		super(radius, pos, kDiffuse, kSpecular, kAmbient, nShineness, isSun, orbitAxis, orbitSpeed, textureFilePath, heightMapFilePath);
	}

	@Override
	public void accept(Visitor visitor) {
		visitor.visit(this);
	}

	public void setParentAbsPos(Point3f p) {
		parentPos = new Point3f(p);
	}

	@Override
	public void recalcAbsPosition() {
		Transform3D transform = new Transform3D();
		transform.setIdentity();

		AxisAngle4f axis = new AxisAngle4f(getOrbitAxis(), getAngle() / 180 * (float) Math.PI);
		Transform3D rotation = new Transform3D();
		rotation.setRotation(axis);

		transform.mul(rotation);

		absPos = new Point3f(getPosition());
		transform.transform(absPos);
		absPos.add(parentPos);

		for (Moon m : getMoons()) {
			m.setParentAbsPos(absPos);
			m.recalcAbsPosition();
		}
	}
}
